package com.hbl.hhb;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class AppReflect {
    public static void main(String[] args) throws Exception{
        Class<?> A=Class.forName("com.hbl.hhb.Animal");
        Object o = A.newInstance();
        Field[] fields = A.getDeclaredFields();
        for (Field field : fields){
            field.setAccessible(true);
            Class<?>type=field.getType();
            if(type.toString().endsWith("String")){
                field.set(o,"Timor");
            }else if(type.toString().endsWith("Integer")){
                field.set(o,2);
            }else if(type.toString().endsWith("Double")){
                field.set(o,3.14);
            }

        }
        Method say=A.getDeclaredMethod("say");
        say.invoke(o);
    }
}
